//
//  RegistViewController.m
//  XLZChat
//
//  Created by dllo on 16/10/21.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "RegistViewController.h"
#import "AVOSCloudIM.h"
#import "UIViewController+ZHWCategory.h"

@interface RegistViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation RegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)registButtonClicked:(UIButton *)sender {
    if (_userNameTextField.text.length > 0 & _passwordTextField.text.length > 0) {
        AVUser *user = [AVUser user];
        user.username = _userNameTextField.text;
        user.password = _passwordTextField.text;
        [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (succeeded) {
                self.passAccount(_userNameTextField.text, _passwordTextField.text);
                [self.navigationController popViewControllerAnimated:YES];
            }
            if (error.code == 202) {
                [self showMessage:@"该用户名已注册"];
            }
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
